package com.yanqu.road.server.manger.cricket.skillhandler.attround.handler;

import com.yanqu.road.entity.cricket.helper.AddHpResult;
import com.yanqu.road.entity.enums.eSkillType;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.gameplayer.module.cricket.battle.CricketGame;
import com.yanqu.road.server.gameplayer.module.cricket.battle.eCricketBattleRoundStep;
import com.yanqu.road.server.gameplayer.module.cricket.model.BattleData;
import com.yanqu.road.server.gameplayer.module.cricket.model.SkillData;
import com.yanqu.road.server.manger.cricket.skillhandler.attround.CricketSkillAttRoundStrategy;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class CricketSkill404Strategy implements CricketSkillAttRoundStrategy {

    /**
     * 技能处理-赵云-银枪掠影：所有快夹替换成亮银枪，使用亮银枪攻击时赵云拥有{0}的几率额外连击一次。
     * @param cricketGame 本局对局对象
     * @param skillData 触发的技能
     * @param baseAttSkill 基础攻击技能
     * @param baseAttReHpResult 基础攻击结果对象
     * @param action 我方
     * @param target 对方
     * @param attackRoundBuilder 返回PB结构体
     * @return true：死亡，退出技能处理，false：继续技能处理
     */
    @Override
    public boolean skillHandle(CricketGame cricketGame, SkillData skillData, SkillData baseAttSkill, AddHpResult baseAttReHpResult, BattleData action, BattleData target, CricketProto.CricketAttackRound.Builder attackRoundBuilder, long battleFrameId) {
        //基础攻击miss，不触发技能
        if (baseAttReHpResult == null) {
            return false;
        }
        //判断是否是快夹
        if (baseAttSkill.getSkillEffect().getSkillType() == eSkillType.CricketBattleSkill137.getValue() && baseAttSkill.getSkillEffect().getP4() == 1) {//1快夹2冲夹3举摔
            //判断是否触发技能-再次攻击
            int compareValue = skillData.getSkillEffect().getP1();
            int randValue = cricketGame.rand1000();
            if (randValue < compareValue) {
                //触发再次攻击技能
                skillData.effectAmountInc();
                //基础攻击技能
                SkillData attackRoundSkill = action.getAttackRoundSkill();
                if (attackRoundSkill != null) {
                    boolean isMiss = cricketGame.attackMiss(attackRoundSkill, target);
                    //攻击
                    cricketGame.attack(action, target, attackRoundSkill, isMiss, attackRoundBuilder);
                    if (cricketGame.isOver(attackRoundBuilder, eCricketBattleRoundStep.AfterAttack.getValue(), 0)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
